<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Partial Updates - The .NET Core ORM Cookbook</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" href="css/theme.css" type="text/css" />
    <link rel="stylesheet" href="css/theme_colors.css" type="text/css" />
    <link rel="stylesheet" href="css/styles/vs.css">
    <link rel="stylesheet" href="css/font-awesome.4.5.0.min.css">
</head>
<body role="document">
    <div class="grid-for-nav">
        <nav data-toggle="nav-shift" class="nav-side stickynav">
            <div class="side-nav-search">
                <a href="index.htm"><i class="fa fa-home"></i> The .NET Core ORM Cookbook</a>
                <div role="search">
                    <form id="search-form" class="form" action="Docnet_search.htm" method="get">
                        <input type="text" name="q" placeholder="Search docs" />
                    </form>
                </div>
            </div>
            <div class="menu menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="tocentry"><a href="index.htm">Home</a>
</li>

<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="ORMs.htm">ORMs</a></span>
</li>
<li class="tocentry"><a href="FAQ.htm">FAQ</a>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="StandardCRUDscenarios.htm">Standard CRUD scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Fetchingdatascenarios.htm">Fetching data scenarios</a></span>
</li>
<li class="tocentry">
<ul>
<li><span class="navigationgroup"><i class="fa fa-caret-down"></i> <a href="Advancedscenarios.htm">Advanced scenarios</a></span></li>
<li class="tocentry"><a href="SingleModelCrudAsync.htm">Async Operations</a>
</li>
<li class="tocentry"><a href="LargeBatch.htm">Batch Inserts with Large Collections</a>
</li>
<li class="tocentry"><a href="BulkInsert.htm">Bulk Inserts</a>
</li>
<li class="tocentry"><a href="ConnectionSharing.htm">Connection Sharing</a>
</li>
<li class="tocentry"><a href="MultipleDB.htm">Multiple Databases</a>
</li>
<li class="tocentry current"><a class="current" href="PartialUpdate.htm">Partial Updates</a>
<ul class="currentrelative">
<li class="tocentry"><a href="#scenario-prototype">Scenario Prototype</a></li>

<li class="tocentry"><a href="#ado.net">ADO.NET</a></li>

<li class="tocentry"><a href="#chain">Chain</a></li>

<li class="tocentry"><a href="#dapper">Dapper</a></li>

<li class="tocentry"><a href="#dbconnector">DbConnector</a></li>

<li class="tocentry"><a href="#entity-framework-6">Entity Framework 6</a></li>

<li class="tocentry"><a href="#entity-framework-core">Entity Framework Core</a></li>

<li class="tocentry"><a href="#linq-to-db">LINQ to DB</a></li>

<li class="tocentry"><a href="#llblgen-pro">LLBLGen Pro</a></li>

<li class="tocentry"><a href="#nhibernate">NHibernate</a></li>

<li class="tocentry"><a href="#repodb">RepoDb</a></li>

<li class="tocentry"><a href="#servicestack">ServiceStack</a></li>



</ul>
<li class="tocentry"><a href="Transactions.htm">Transactions</a>
</li>
<li class="tocentry"><a href="Upsert.htm">Upsert</a>
</li>

</ul>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Sortingscenarios.htm">Sorting scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Storedprocedurescenarios.htm">Stored procedure scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Auditingandhistoryscenarios.htm">Auditing and history scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="Multi-Tenancyscenarios.htm">Multi-Tenancy scenarios</a></span>
</li>
<li class="tocentry">
<span class="navigationgroup"><i class="fa fa-caret-right"></i> <a href="UnknownDatabasescenarios.htm">Unknown Database scenarios</a></span>
</li>
</ul>
				<div class="toc-footer">
					<span class="text-small">
						<hr/>
						<a href="https://github.com/FransBouma/DocNet" target="_blank">Made with <i class="fa fa-github"></i> DocNet</a>
					</span>
				</div>	
			</div>
            &nbsp;
        </nav>
        <section data-toggle="nav-shift" class="nav-content-wrap">
            <nav class="nav-top" role="navigation" aria-label="top navigation">
                <i data-toggle="nav-top" class="fa fa-bars"></i>
                <a href="index.htm">The .NET Core ORM Cookbook</a>
            </nav>
            <div class="nav-content">
                <div role="navigation" aria-label="breadcrumbs navigation">
                    <div class="breadcrumbs">
<ul><li><a href="index.htm">Home</a></li> / <li><a href="Advancedscenarios.htm">Advanced scenarios</a></li> / <li><a href="PartialUpdate.htm">Partial Updates</a></li></ul>
					
                    </div>
                    <hr />
                </div>
                <div role="main">
                    <div class="section">
<h1 id="partial-updates">Partial Updates<a class="headerlink" href="#partial-updates" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h1>
<p>These scenarios demonstrate how to perform partial updates on a row. </p>
<h2 id="scenario-prototype">Scenario Prototype<a class="headerlink" href="#scenario-prototype" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage);

void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage);
</code></pre>

<pre><code class="cs">void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee);
</code></pre>

<h2 id="ado.net">ADO.NET<a class="headerlink" href="#ado.net" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET EmployeeClassificationName = @EmployeeClassificationName
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
    using (var cmd = new SqlCommand(sql, con))
    {
        cmd.Parameters.AddWithValue(&quot;@EmployeeClassificationKey&quot;, updateMessage.EmployeeClassificationKey);
        cmd.Parameters.AddWithValue(&quot;@EmployeeClassificationName&quot;, updateMessage.EmployeeClassificationName);
        cmd.ExecuteNonQuery();
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @IsExempt, IsEmployee = @IsEmployee
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
    using (var cmd = new SqlCommand(sql, con))
    {
        cmd.Parameters.AddWithValue(&quot;@EmployeeClassificationKey&quot;, updateMessage.EmployeeClassificationKey);
        cmd.Parameters.AddWithValue(&quot;@IsExempt&quot;, updateMessage.IsExempt);
        cmd.Parameters.AddWithValue(&quot;@IsEmployee&quot;, updateMessage.IsEmployee);
        cmd.ExecuteNonQuery();
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @IsExempt, IsEmployee = @IsEmployee
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
    using (var cmd = new SqlCommand(sql, con))
    {
        cmd.Parameters.AddWithValue(&quot;@EmployeeClassificationKey&quot;, employeeClassificationKey);
        cmd.Parameters.AddWithValue(&quot;@IsExempt&quot;, isExempt);
        cmd.Parameters.AddWithValue(&quot;@IsEmployee&quot;, isEmployee);
        cmd.ExecuteNonQuery();
    }
}
</code></pre>

<h2 id="chain">Chain<a class="headerlink" href="#chain" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    m_DataSource.Update(updateMessage).Execute();
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    m_DataSource.Update(updateMessage).Execute();
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    m_DataSource.Update(TableName, new { employeeClassificationKey, isExempt, isEmployee }).Execute();
}
</code></pre>

<h2 id="dapper">Dapper<a class="headerlink" href="#dapper" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    var sql = @&quot;UPDATE HR.EmployeeClassification
                SET EmployeeClassificationName = @EmployeeClassificationName
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
        con.Execute(sql, updateMessage);
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    var sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @IsExempt, IsEmployee = @IsEmployee
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
        con.Execute(sql, updateMessage);
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    var sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @IsExempt, IsEmployee = @IsEmployee
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    using (var con = OpenConnection())
        con.Execute(sql, new { employeeClassificationKey, isExempt, isEmployee });
}
</code></pre>

<h2 id="dbconnector">DbConnector<a class="headerlink" href="#dbconnector" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET EmployeeClassificationName = @EmployeeClassificationName
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    DbConnector.NonQuery(sql, updateMessage).Execute();
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @IsExempt, IsEmployee = @IsEmployee
                WHERE EmployeeClassificationKey = @EmployeeClassificationKey;&quot;;

    DbConnector.NonQuery(sql, updateMessage).Execute();
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    const string sql = @&quot;UPDATE HR.EmployeeClassification
                SET IsExempt = @isExempt, IsEmployee = @isEmployee
                WHERE EmployeeClassificationKey = @employeeClassificationKey;&quot;;

    DbConnector.NonQuery(sql, new { employeeClassificationKey, isExempt, isEmployee }).Execute();
}
</code></pre>

<h2 id="entity-framework-6">Entity Framework 6<a class="headerlink" href="#entity-framework-6" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>To perform a partial update, first fetch a record and then modify it.</p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var context = CreateDbContext())
    {
        //Get a fresh copy of the row from the database
        var temp = context.EmployeeClassification.Find(updateMessage.EmployeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.EmployeeClassificationName = updateMessage.EmployeeClassificationName;
            context.SaveChanges();
        }
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var context = CreateDbContext())
    {
        //Get a fresh copy of the row from the database
        var temp = context.EmployeeClassification.Find(updateMessage.EmployeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.IsExempt = updateMessage.IsExempt;
            temp.IsEmployee = updateMessage.IsEmployee;
            context.SaveChanges();
        }
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var context = CreateDbContext())
    {
        //Get a fresh copy of the row from the database
        var temp = context.EmployeeClassification.Find(employeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.IsExempt = isExempt;
            temp.IsEmployee = isEmployee;
            context.SaveChanges();
        }
    }
}
</code></pre>

<h2 id="entity-framework-core">Entity Framework Core<a class="headerlink" href="#entity-framework-core" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>To perform a partial update, first fetch a record and then modify it.</p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var context = CreateDbContext())
    {
        //Get a fresh copy of the row from the database
        var temp = context.EmployeeClassifications.Find(updateMessage.EmployeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.EmployeeClassificationName = updateMessage.EmployeeClassificationName;
            context.SaveChanges();
        }
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var context = CreateDbContext())
    {
        var temp = new EmployeeClassification();
        temp.EmployeeClassificationKey = updateMessage.EmployeeClassificationKey;
        temp.IsExempt = updateMessage.IsExempt;
        temp.IsEmployee = updateMessage.IsEmployee;
        context.Entry&lt;EmployeeClassification&gt;(temp).Property(x =&gt; x.IsExempt).IsModified = true;
        context.Entry&lt;EmployeeClassification&gt;(temp).Property(x =&gt; x.IsEmployee).IsModified = true;
        context.SaveChanges();

        /*
              //Get a fresh copy of the row from the database
              var temp = context.EmployeeClassification.Find(updateMessage.EmployeeClassificationKey);
              if (temp != null)
              {
                  //Copy the changed fields
                  temp.IsExempt = updateMessage.IsExempt;
                  temp.IsEmployee = updateMessage.IsEmployee;
                  context.SaveChanges();
              }
              */
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var context = CreateDbContext())
    {
        //Get a fresh copy of the row from the database
        var temp = context.EmployeeClassifications.Find(employeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.IsExempt = isExempt;
            temp.IsEmployee = isEmployee;
            context.SaveChanges();
        }
    }
}
</code></pre>

<h2 id="linq-to-db">LINQ to DB<a class="headerlink" href="#linq-to-db" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var db = new OrmCookbook())
    {
        db.EmployeeClassification
            .Where(ec =&gt; ec.EmployeeClassificationKey == updateMessage.EmployeeClassificationKey)
            .Set(ec =&gt; ec.EmployeeClassificationName, updateMessage.EmployeeClassificationName)
            .Update();
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var db = new OrmCookbook())
    {
        db.EmployeeClassification
            .Where(ec =&gt; ec.EmployeeClassificationKey == updateMessage.EmployeeClassificationKey)
            .Set(ec =&gt; ec.IsExempt, updateMessage.IsExempt)
            .Set(ec =&gt; ec.IsEmployee, updateMessage.IsEmployee)
            .Update();
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var db = new OrmCookbook())
    {
        db.EmployeeClassification
            .Where(ec =&gt; ec.EmployeeClassificationKey == employeeClassificationKey)
            .Set(ec =&gt; ec.IsExempt, isExempt)
            .Set(ec =&gt; ec.IsEmployee, isEmployee)
            .Update();
    }
}
</code></pre>

<h2 id="llblgen-pro">LLBLGen Pro<a class="headerlink" href="#llblgen-pro" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>To perform a partial update, you can decide to first fetch a record and then modify it, or to update directly without fetching 
it first. </p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var adapter = new DataAccessAdapter())
    {
        // use an entity
        var temp = adapter.FetchFirst(new QueryFactory().EmployeeClassification
                                .Where(EmployeeClassificationFields.EmployeeClassificationKey
                                                                   .Equal(updateMessage.EmployeeClassificationKey)));
        if (temp != null)
        {
            temp.EmployeeClassificationName = updateMessage.EmployeeClassificationName;
            adapter.SaveEntity(temp);
        }
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var adapter = new DataAccessAdapter())
    {
        // for kicks, update the entity directly in the DB, without fetching one first.
        var updater = new EmployeeClassificationEntity();
        updater.IsEmployee = updateMessage.IsEmployee;
        updater.IsExempt = updateMessage.IsExempt;
        adapter.UpdateEntitiesDirectly(updater, 
               new RelationPredicateBucket(EmployeeClassificationFields.EmployeeClassificationKey
                                                                       .Equal(updateMessage.EmployeeClassificationKey)));
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var adapter = new DataAccessAdapter())
    {
        // let's use Linq for a change...
        var temp = new LinqMetaData(adapter).EmployeeClassification.FirstOrDefault(ec =&gt; ec.EmployeeClassificationKey == employeeClassificationKey);
        if (temp != null)
        {
            //Copy the changed fields
            temp.IsExempt = isExempt;
            temp.IsEmployee = isEmployee;
            adapter.SaveEntity(temp);
        }
    }
}
</code></pre>

<h2 id="nhibernate">NHibernate<a class="headerlink" href="#nhibernate" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>To perform a partial update, first fetch a record and then modify it.</p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var session = m_SessionFactory.OpenSession())
    {
        var temp = session.Get&lt;EmployeeClassification&gt;(updateMessage.EmployeeClassificationKey);
        if (temp != null)
        {
            temp.EmployeeClassificationName = updateMessage.EmployeeClassificationName;
            session.Update(temp);
            session.Flush();
        }
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var session = m_SessionFactory.OpenSession())
    {
        var temp = session.Get&lt;EmployeeClassification&gt;(updateMessage.EmployeeClassificationKey);
        if (temp != null)
        {
            temp.IsExempt = updateMessage.IsExempt;
            temp.IsEmployee = updateMessage.IsEmployee;
            session.Update(temp);
            session.Flush();
        }
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var session = m_SessionFactory.OpenSession())
    {
        var temp = session.Get&lt;EmployeeClassification&gt;(employeeClassificationKey);
        if (temp != null)
        {
            temp.IsExempt = isExempt;
            temp.IsEmployee = isEmployee;
            session.Update(temp);
            session.Flush();
        }
    }
}
</code></pre>

<h2 id="repodb">RepoDb<a class="headerlink" href="#repodb" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>In RepoDb, you can either do the following.</p>
<ul>
<li>Limit the properties of your entity model for targetted columns.</li>
<li>Specify the name of the targe table and pass the object (or <em>dynamic</em>).</li>
</ul>
<p>The <em>ClassMappedNameCache</em> class  will help you extract the target table from the original entity.</p>
<p>Code snippets below resembles item #2 above.</p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var connection = CreateConnection(true))
    {
        connection.Update(ClassMappedNameCache.Get&lt;EmployeeClassification&gt;(), updateMessage);
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var connection = CreateConnection(true))
    {
        connection.Update(ClassMappedNameCache.Get&lt;EmployeeClassification&gt;(), updateMessage);
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var connection = CreateConnection(true))
    {
        connection.Update(ClassMappedNameCache.Get&lt;EmployeeClassification&gt;(),
            new { employeeClassificationKey, isExempt, isEmployee });
    }
}
</code></pre>

<h2 id="servicestack">ServiceStack<a class="headerlink" href="#servicestack" title="Permalink to this headline"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<p>In ServiceStack, partial updates have to be 'unpacked'. Updated columns are passed in one parameter and filter column(s) (e.g. primary key) in a separate parameter.</p>
<pre><code class="cs">public void UpdateWithObject(EmployeeClassificationNameUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var db = _dbConnectionFactory.OpenDbConnection())
    {
        db.Update&lt;EmployeeClassificationPartial&gt;(
            new { updateMessage.EmployeeClassificationName },
            r =&gt; r.Id == updateMessage.EmployeeClassificationKey);
    }
}

public void UpdateWithObject(EmployeeClassificationFlagsUpdater updateMessage)
{
    if (updateMessage == null)
        throw new ArgumentNullException(nameof(updateMessage), $&quot;{nameof(updateMessage)} is null.&quot;);

    using (var db = _dbConnectionFactory.OpenDbConnection())
    {
        db.Update&lt;EmployeeClassificationPartial&gt;(
            new { updateMessage.IsEmployee, updateMessage.IsExempt },
            r =&gt; r.Id == updateMessage.EmployeeClassificationKey);
    }
}
</code></pre>

<pre><code class="cs">public void UpdateWithSeparateParameters(int employeeClassificationKey, bool isExempt, bool isEmployee)
{
    using (var db = _dbConnectionFactory.OpenDbConnection())
    {
        db.Update&lt;EmployeeClassificationPartial&gt;(
            new { isExempt, isEmployee },
            r =&gt; r.Id == employeeClassificationKey);
    }
}
</code></pre>


                    </div>
                </div>
                <footer>
                    <hr />
                    <div role="contentinfo">
The ORM Cookbook. <a href='https://github.com/Grauenwolf/DotNet-ORM-Cookbook' target='_blank'>Visit us at GitHub</a>.
                    </div>
                </footer>
            </div>
        </section>
    </div>
    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/modernizr-2.8.3.min.js"></script>
    <script src="js/highlight.pack.js"></script>
    <script src="js/theme.js"></script>

</body>
</html>
